package p0;

public class Leetcode_7 {
    public int reverse(int x) {
        boolean b = x >= 0;
        StringBuilder sb = new StringBuilder(String.valueOf(x));
        long l = b ? Long.valueOf(sb.reverse().toString()) : Long.valueOf(sb.deleteCharAt(0).reverse().toString());
        if (l > Integer.MAX_VALUE || l < Integer.MIN_VALUE) {
            return 0;
        } else {
            return b ? Integer.valueOf(sb.toString()) : 0 - Integer.valueOf(sb.toString());
        }
    }
}